package com.gxaedu.shiro.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;

public class ValidateUtil {


    /**
     * 获取验证的错误信息
     * @param result
     * @return
     */
    public static String getErrorMsg(BindingResult result){
        String errors = "";
        if (result.hasErrors()) {
            // 准备一个错误的字符串
            List<ObjectError> allErrors = result.getAllErrors();
            for (ObjectError allError : allErrors) {
                errors += allError.getDefaultMessage()+";";
            }
        }
        return errors;
    }

}
